home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-29 | 55.2 KB | 1,829 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i057: gnucalc - GNU Emacs Calculator, v2.00, Part09/56
- Message-ID: <1991Oct29.225947.20060@sparky.imd.sterling.com>
- X-Md4-Signature: 88c6cc81bcf6453dc52b9e2f55c8f80b
- Date: Tue, 29 Oct 1991 22:59:47 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 57
- Archive-name: gnucalc/part09
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # this is Part.09 (part 9 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc-arith.el continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 9; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc-arith.el'
- else
- echo 'x - continuing file calc-arith.el'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc-arith.el' &&
- )
- X
- ;;; Fast function to multiply floating-point numbers.
- (defun math-mul-float (a b) ; [F F F]
- X (math-make-float (math-mul (nth 1 a) (nth 1 b))
- X (+ (nth 2 a) (nth 2 b)))
- )
- X
- (defun math-sqr-float (a) ; [F F]
- X (math-make-float (math-mul (nth 1 a) (nth 1 a))
- X (+ (nth 2 a) (nth 2 a)))
- )
- X
- (defun math-intv-constp (a &optional finite)
- X (and (or (Math-anglep (nth 2 a))
- X (and (equal (nth 2 a) '(neg (var inf var-inf)))
- X (or (not finite)
- X (memq (nth 1 a) '(0 1)))))
- X (or (Math-anglep (nth 3 a))
- X (and (equal (nth 3 a) '(var inf var-inf))
- X (or (not finite)
- X (memq (nth 1 a) '(0 2))))))
- )
- X
- (defun math-mul-zero (a b)
- X (if (math-known-matrixp b)
- X (if (math-vectorp b)
- X (math-map-vec-2 'math-mul a b)
- X (math-mimic-ident 0 b))
- X (if (math-infinitep b)
- X '(var nan var-nan)
- X (let ((aa nil) (bb nil))
- X (if (and (eq (car-safe b) 'intv)
- X (progn
- X (and (equal (nth 2 b) '(neg (var inf var-inf)))
- X (memq (nth 1 b) '(2 3))
- X (setq aa (nth 2 b)))
- X (and (equal (nth 3 b) '(var inf var-inf))
- X (memq (nth 1 b) '(1 3))
- X (setq bb (nth 3 b)))
- X (or aa bb)))
- X (if (or (math-posp a)
- X (and (math-zerop a)
- X (or (memq calc-infinite-mode '(-1 1))
- X (setq aa '(neg (var inf var-inf))
- X bb '(var inf var-inf)))))
- X (list 'intv 3 (or aa 0) (or bb 0))
- X (if (math-negp a)
- X (math-neg (list 'intv 3 (or aa 0) (or bb 0)))
- X '(var nan var-nan)))
- X (if (or (math-floatp a) (math-floatp b)) '(float 0 0) 0)))))
- )
- X
- X
- (defun math-mul-symb-fancy (a b)
- X (or (and math-simplify-only
- X (not (equal a math-simplify-only))
- X (list '* a b))
- X (and (Math-equal-int a 1)
- X b)
- X (and (Math-equal-int a -1)
- X (math-neg b))
- X (and (or (and (Math-vectorp a) (math-known-scalarp b))
- X (and (Math-vectorp b) (math-known-scalarp a)))
- X (math-map-vec-2 'math-mul a b))
- X (and (Math-objectp b)
- X (math-mul b a))
- X (and (eq (car-safe a) 'neg)
- X (math-neg (math-mul (nth 1 a) b)))
- X (and (eq (car-safe b) 'neg)
- X (math-neg (math-mul a (nth 1 b))))
- X (and (eq (car-safe a) '*)
- X (math-mul (nth 1 a)
- X (math-mul (nth 2 a) b)))
- X (and (eq (car-safe a) '^)
- X (Math-looks-negp (nth 2 a))
- X (not (and (eq (car-safe b) '^) (Math-looks-negp (nth 2 b))))
- X (math-known-scalarp b t)
- X (math-div b (math-normalize
- X (list '^ (nth 1 a) (math-neg (nth 2 a))))))
- X (and (eq (car-safe b) '^)
- X (Math-looks-negp (nth 2 b))
- X (not (and (eq (car-safe a) '^) (Math-looks-negp (nth 2 a))))
- X (math-div a (math-normalize
- X (list '^ (nth 1 b) (math-neg (nth 2 b))))))
- X (and (eq (car-safe a) '/)
- X (or (math-known-scalarp a t) (math-known-scalarp b t))
- X (let ((temp (math-combine-prod (nth 2 a) b t nil t)))
- X (if temp
- X (math-mul (nth 1 a) temp)
- X (math-div (math-mul (nth 1 a) b) (nth 2 a)))))
- X (and (eq (car-safe b) '/)
- X (math-div (math-mul a (nth 1 b)) (nth 2 b)))
- X (and (eq (car-safe b) '+)
- X (Math-numberp a)
- X (or (Math-numberp (nth 1 b))
- X (Math-numberp (nth 2 b)))
- X (math-add (math-mul a (nth 1 b))
- X (math-mul a (nth 2 b))))
- X (and (eq (car-safe b) '-)
- X (Math-numberp a)
- X (or (Math-numberp (nth 1 b))
- X (Math-numberp (nth 2 b)))
- X (math-sub (math-mul a (nth 1 b))
- X (math-mul a (nth 2 b))))
- X (and (eq (car-safe b) '*)
- X (Math-numberp (nth 1 b))
- X (not (Math-numberp a))
- X (math-mul (nth 1 b) (math-mul a (nth 2 b))))
- X (and (eq (car-safe a) 'calcFunc-idn)
- X (= (length a) 2)
- X (or (and (eq (car-safe b) 'calcFunc-idn)
- X (= (length b) 2)
- X (list 'calcFunc-idn (math-mul (nth 1 a) (nth 1 b))))
- X (and (math-known-scalarp b)
- X (list 'calcFunc-idn (math-mul (nth 1 a) b)))
- X (and (math-known-matrixp b)
- X (math-mul (nth 1 a) b))))
- X (and (eq (car-safe b) 'calcFunc-idn)
- X (= (length b) 2)
- X (or (and (math-known-scalarp a)
- X (list 'calcFunc-idn (math-mul a (nth 1 b))))
- X (and (math-known-matrixp a)
- X (math-mul a (nth 1 b)))))
- X (and (math-looks-negp b)
- X (math-mul (math-neg a) (math-neg b)))
- X (and (eq (car-safe b) '-)
- X (math-looks-negp a)
- X (math-mul (math-neg a) (math-neg b)))
- X (cond
- X ((eq (car-safe b) '*)
- X (let ((temp (math-combine-prod a (nth 1 b) nil nil t)))
- X (and temp
- X (math-mul temp (nth 2 b)))))
- X (t
- X (math-combine-prod a b nil nil nil)))
- X (and (equal a '(var nan var-nan))
- X a)
- X (and (equal b '(var nan var-nan))
- X b)
- X (and (equal a '(var uinf var-uinf))
- X a)
- X (and (equal b '(var uinf var-uinf))
- X b)
- X (and (equal b '(var inf var-inf))
- X (let ((s1 (math-possible-signs a)))
- X (cond ((eq s1 4)
- X b)
- X ((eq s1 6)
- X '(intv 3 0 (var inf var-inf)))
- X ((eq s1 1)
- X (math-neg b))
- X ((eq s1 3)
- X '(intv 3 (neg (var inf var-inf)) 0))
- X ((and (eq (car a) 'intv) (math-intv-constp a))
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf)))
- X ((and (eq (car a) 'cplx)
- X (math-zerop (nth 1 a)))
- X (list '* (list 'cplx 0 (calcFunc-sign (nth 2 a))) b))
- X ((eq (car a) 'polar)
- X (list '* (list 'polar 1 (nth 2 a)) b)))))
- X (and (equal a '(var inf var-inf))
- X (math-mul b a))
- X (list '* a b))
- )
- X
- X
- (defun calcFunc-div (a &rest rest)
- X (while rest
- X (setq a (list '/ a (car rest))
- X rest (cdr rest)))
- X (math-normalize a)
- )
- X
- (defun math-div-objects-fancy (a b)
- X (cond ((and (Math-numberp a) (Math-numberp b))
- X (math-normalize
- X (cond ((math-want-polar a b)
- X (let ((a (math-polar a))
- X (b (math-polar b)))
- X (list 'polar
- X (math-div (nth 1 a) (nth 1 b))
- X (math-fix-circular (math-sub (nth 2 a)
- X (nth 2 b))))))
- X ((Math-realp b)
- X (setq a (math-complex a))
- X (list 'cplx (math-div (nth 1 a) b)
- X (math-div (nth 2 a) b)))
- X (t
- X (setq a (math-complex a)
- X b (math-complex b))
- X (math-div
- X (list 'cplx
- X (math-add (math-mul (nth 1 a) (nth 1 b))
- X (math-mul (nth 2 a) (nth 2 b)))
- X (math-sub (math-mul (nth 2 a) (nth 1 b))
- X (math-mul (nth 1 a) (nth 2 b))))
- X (math-add (math-sqr (nth 1 b))
- X (math-sqr (nth 2 b))))))))
- X ((math-matrixp b)
- X (if (math-square-matrixp b)
- X (let ((n1 (length b)))
- X (if (Math-vectorp a)
- X (if (math-matrixp a)
- X (if (= (length a) n1)
- X (math-lud-solve (math-matrix-lud b) a b)
- X (if (= (length (nth 1 a)) n1)
- X (math-transpose
- X (math-lud-solve (math-matrix-lud
- X (math-transpose b))
- X (math-transpose a) b))
- X (math-dimension-error)))
- X (if (= (length a) n1)
- X (math-mat-col (math-lud-solve (math-matrix-lud b)
- X (math-col-matrix a) b)
- X 1)
- X (math-dimension-error)))
- X (if (Math-equal-int a 1)
- X (calcFunc-inv b)
- X (math-mul a (calcFunc-inv b)))))
- X (math-reject-arg b 'square-matrixp)))
- X ((and (Math-vectorp a) (Math-objectp b))
- X (math-map-vec-2 'math-div a b))
- X ((eq (car-safe a) 'sdev)
- X (if (eq (car-safe b) 'sdev)
- X (let ((x (math-div (nth 1 a) (nth 1 b))))
- X (math-make-sdev x
- X (math-div (math-hypot (nth 2 a)
- X (math-mul (nth 2 b) x))
- X (nth 1 b))))
- X (if (or (Math-scalarp b)
- X (not (Math-objvecp b)))
- X (math-make-sdev (math-div (nth 1 a) b) (math-div (nth 2 a) b))
- X (math-reject-arg 'realp b))))
- X ((and (eq (car-safe b) 'sdev)
- X (or (Math-scalarp a)
- X (not (Math-objvecp a))))
- X (let ((x (math-div a (nth 1 b))))
- X (math-make-sdev x
- X (math-div (math-mul (nth 2 b) x) (nth 1 b)))))
- X ((and (eq (car-safe a) 'intv) (Math-anglep b))
- X (if (Math-negp b)
- X (math-neg (math-div a (math-neg b)))
- X (math-make-intv (nth 1 a)
- X (math-div (nth 2 a) b)
- X (math-div (nth 3 a) b))))
- X ((and (eq (car-safe b) 'intv) (Math-anglep a))
- X (if (or (Math-posp (nth 2 b))
- X (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1))
- X calc-infinite-mode)))
- X (if (Math-negp a)
- X (math-neg (math-div (math-neg a) b))
- X (let ((calc-infinite-mode 1))
- X (math-make-intv (aref [0 2 1 3] (nth 1 b))
- X (math-div a (nth 3 b))
- X (math-div a (nth 2 b)))))
- X (if (or (Math-negp (nth 3 b))
- X (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2))
- X calc-infinite-mode)))
- X (math-neg (math-div a (math-neg b)))
- X (if calc-infinite-mode
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
- X (math-reject-arg b "*Division by zero")))))
- X ((and (eq (car-safe a) 'intv) (math-intv-constp a)
- X (eq (car-safe b) 'intv) (math-intv-constp b))
- X (if (or (Math-posp (nth 2 b))
- X (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1))
- X calc-infinite-mode)))
- X (let* ((calc-infinite-mode 1)
- X (lo (math-div a (nth 2 b)))
- X (hi (math-div a (nth 3 b))))
- X (or (eq (car-safe lo) 'intv)
- X (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0)
- X lo lo)))
- X (or (eq (car-safe hi) 'intv)
- X (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0)
- X hi hi)))
- X (math-combine-intervals
- X (nth 2 lo) (and (or (memq (nth 1 b) '(2 3))
- X (and (math-infinitep (nth 2 lo))
- X (not (math-zerop (nth 2 b)))))
- X (memq (nth 1 lo) '(2 3)))
- X (nth 3 lo) (and (or (memq (nth 1 b) '(2 3))
- X (and (math-infinitep (nth 3 lo))
- X (not (math-zerop (nth 2 b)))))
- X (memq (nth 1 lo) '(1 3)))
- X (nth 2 hi) (and (or (memq (nth 1 b) '(1 3))
- X (and (math-infinitep (nth 2 hi))
- X (not (math-zerop (nth 3 b)))))
- X (memq (nth 1 hi) '(2 3)))
- X (nth 3 hi) (and (or (memq (nth 1 b) '(1 3))
- X (and (math-infinitep (nth 3 hi))
- X (not (math-zerop (nth 3 b)))))
- X (memq (nth 1 hi) '(1 3)))))
- X (if (or (Math-negp (nth 3 b))
- X (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2))
- X calc-infinite-mode)))
- X (math-neg (math-div a (math-neg b)))
- X (if calc-infinite-mode
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
- X (math-reject-arg b "*Division by zero")))))
- X ((and (eq (car-safe a) 'mod)
- X (eq (car-safe b) 'mod)
- X (equal (nth 2 a) (nth 2 b)))
- X (math-make-mod (math-div-mod (nth 1 a) (nth 1 b) (nth 2 a))
- X (nth 2 a)))
- X ((and (eq (car-safe a) 'mod)
- X (Math-anglep b))
- X (math-make-mod (math-div-mod (nth 1 a) b (nth 2 a)) (nth 2 a)))
- X ((and (eq (car-safe b) 'mod)
- X (Math-anglep a))
- X (math-make-mod (math-div-mod a (nth 1 b) (nth 2 b)) (nth 2 b)))
- X ((eq (car-safe a) 'hms)
- X (if (eq (car-safe b) 'hms)
- X (math-with-extra-prec 1
- X (math-div (math-from-hms a 'deg)
- X (math-from-hms b 'deg)))
- X (math-with-extra-prec 2
- X (math-to-hms (math-div (math-from-hms a 'deg) b) 'deg))))
- X (t (calc-record-why "*Incompatible arguments for /" a b)))
- )
- X
- (defun math-div-by-zero (a b)
- X (if (math-infinitep a)
- X (if (or (equal a '(var nan var-nan))
- X (equal b '(var uinf var-uinf))
- X (memq calc-infinite-mode '(-1 1)))
- X a
- X '(var uinf var-uinf))
- X (if calc-infinite-mode
- X (if (math-zerop a)
- X '(var nan var-nan)
- X (if (eq calc-infinite-mode 1)
- X (math-mul a '(var inf var-inf))
- X (if (eq calc-infinite-mode -1)
- X (math-mul a '(neg (var inf var-inf)))
- X (if (eq (car-safe a) 'intv)
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
- X '(var uinf var-uinf)))))
- X (math-reject-arg a "*Division by zero")))
- )
- X
- (defun math-div-zero (a b)
- X (if (math-known-matrixp b)
- X (if (math-vectorp b)
- X (math-map-vec-2 'math-div a b)
- X (math-mimic-ident 0 b))
- X (if (equal b '(var nan var-nan))
- X b
- X (if (and (eq (car-safe b) 'intv) (math-intv-constp b)
- X (not (math-posp b)) (not (math-negp b)))
- X (if calc-infinite-mode
- X (list 'intv 3
- X (if (and (math-zerop (nth 2 b))
- X (memq calc-infinite-mode '(1 -1)))
- X (nth 2 b) '(neg (var inf var-inf)))
- X (if (and (math-zerop (nth 3 b))
- X (memq calc-infinite-mode '(1 -1)))
- X (nth 3 b) '(var inf var-inf)))
- X (math-reject-arg b "*Division by zero"))
- X a)))
- )
- X
- (defun math-div-symb-fancy (a b)
- X (or (and math-simplify-only
- X (not (equal a math-simplify-only))
- X (list '/ a b))
- X (and (Math-equal-int b 1) a)
- X (and (Math-equal-int b -1) (math-neg a))
- X (and (Math-vectorp a) (math-known-scalarp b)
- X (math-map-vec-2 'math-div a b))
- X (and (eq (car-safe b) '^)
- X (or (Math-looks-negp (nth 2 b)) (Math-equal-int a 1))
- X (math-mul a (math-normalize
- X (list '^ (nth 1 b) (math-neg (nth 2 b))))))
- X (and (eq (car-safe a) 'neg)
- X (math-neg (math-div (nth 1 a) b)))
- X (and (eq (car-safe b) 'neg)
- X (math-neg (math-div a (nth 1 b))))
- X (and (eq (car-safe a) '/)
- X (math-div (nth 1 a) (math-mul (nth 2 a) b)))
- X (and (eq (car-safe b) '/)
- X (or (math-known-scalarp (nth 1 b) t)
- X (math-known-scalarp (nth 2 b) t))
- X (math-div (math-mul a (nth 2 b)) (nth 1 b)))
- X (and (eq (car-safe b) 'frac)
- X (math-mul (math-make-frac (nth 2 b) (nth 1 b)) a))
- X (and (eq (car-safe a) '+)
- X (or (Math-numberp (nth 1 a))
- X (Math-numberp (nth 2 a)))
- X (Math-numberp b)
- X (math-add (math-div (nth 1 a) b)
- X (math-div (nth 2 a) b)))
- X (and (eq (car-safe a) '-)
- X (or (Math-numberp (nth 1 a))
- X (Math-numberp (nth 2 a)))
- X (Math-numberp b)
- X (math-sub (math-div (nth 1 a) b)
- X (math-div (nth 2 a) b)))
- X (and (or (eq (car-safe a) '-)
- X (math-looks-negp a))
- X (math-looks-negp b)
- X (math-div (math-neg a) (math-neg b)))
- X (and (eq (car-safe b) '-)
- X (math-looks-negp a)
- X (math-div (math-neg a) (math-neg b)))
- X (and (eq (car-safe a) 'calcFunc-idn)
- X (= (length a) 2)
- X (or (and (eq (car-safe b) 'calcFunc-idn)
- X (= (length b) 2)
- X (list 'calcFunc-idn (math-div (nth 1 a) (nth 1 b))))
- X (and (math-known-scalarp b)
- X (list 'calcFunc-idn (math-div (nth 1 a) b)))
- X (and (math-known-matrixp b)
- X (math-div (nth 1 a) b))))
- X (and (eq (car-safe b) 'calcFunc-idn)
- X (= (length b) 2)
- X (or (and (math-known-scalarp a)
- X (list 'calcFunc-idn (math-div a (nth 1 b))))
- X (and (math-known-matrixp a)
- X (math-div a (nth 1 b)))))
- X (if (and calc-matrix-mode
- X (or (math-known-matrixp a) (math-known-matrixp b)))
- X (math-combine-prod a b nil t nil)
- X (if (eq (car-safe a) '*)
- X (if (eq (car-safe b) '*)
- X (let ((c (math-combine-prod (nth 1 a) (nth 1 b) nil t t)))
- X (and c
- X (math-div (math-mul c (nth 2 a)) (nth 2 b))))
- X (let ((c (math-combine-prod (nth 1 a) b nil t t)))
- X (and c
- X (math-mul c (nth 2 a)))))
- X (if (eq (car-safe b) '*)
- X (let ((c (math-combine-prod a (nth 1 b) nil t t)))
- X (and c
- X (math-div c (nth 2 b))))
- X (math-combine-prod a b nil t nil))))
- X (and (math-infinitep a)
- X (if (math-infinitep b)
- X '(var nan var-nan)
- X (if (or (equal a '(var nan var-nan))
- X (equal a '(var uinf var-uinf)))
- X a
- X (if (equal a '(var inf var-inf))
- X (if (or (math-posp b)
- X (and (eq (car-safe b) 'intv)
- X (math-zerop (nth 2 b))))
- X (if (and (eq (car-safe b) 'intv)
- X (not (math-intv-constp b t)))
- X '(intv 3 0 (var inf var-inf))
- X a)
- X (if (or (math-negp b)
- X (and (eq (car-safe b) 'intv)
- X (math-zerop (nth 3 b))))
- X (if (and (eq (car-safe b) 'intv)
- X (not (math-intv-constp b t)))
- X '(intv 3 (neg (var inf var-inf)) 0)
- X (math-neg a))
- X (if (and (eq (car-safe b) 'intv)
- X (math-negp (nth 2 b)) (math-posp (nth 3 b)))
- X '(intv 3 (neg (var inf var-inf))
- X (var inf var-inf)))))))))
- X (and (math-infinitep b)
- X (if (equal b '(var nan var-nan))
- X b
- X (let ((calc-infinite-mode 1))
- X (math-mul-zero b a))))
- X (list '/ a b))
- )
- X
- X
- (defun calcFunc-mod (a b)
- X (math-normalize (list '% a b))
- )
- X
- (defun math-mod-fancy (a b)
- X (cond ((equal b '(var inf var-inf))
- X (if (or (math-posp a) (math-zerop a))
- X a
- X (if (math-negp a)
- X b
- X (if (eq (car-safe a) 'intv)
- X (if (math-negp (nth 2 a))
- X '(intv 3 0 (var inf var-inf))
- X a)
- X (list '% a b)))))
- X ((and (eq (car-safe a) 'mod) (Math-realp b) (math-posp b))
- X (math-make-mod (nth 1 a) b))
- X ((and (eq (car-safe a) 'intv) (math-intv-constp a t) (math-posp b))
- X (math-mod-intv a b))
- X (t
- X (if (Math-anglep a)
- X (calc-record-why 'anglep b)
- X (calc-record-why 'anglep a))
- X (list '% a b)))
- )
- X
- X
- (defun calcFunc-pow (a b)
- X (math-normalize (list '^ a b))
- )
- X
- (defun math-pow-of-zero (a b)
- X (if (Math-zerop b)
- X (if calc-infinite-mode
- X '(var nan var-nan)
- X (math-reject-arg (list '^ a b) "*Indeterminate form"))
- X (if (math-floatp b) (setq a (math-float a)))
- X (if (math-posp b)
- X a
- X (if (math-negp b)
- X (math-div 1 a)
- X (if (math-infinitep b)
- X '(var nan var-nan)
- X (if (and (eq (car b) 'intv) (math-intv-constp b)
- X calc-infinite-mode)
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
- X (if (math-objectp b)
- X (list '^ a b)
- X a))))))
- )
- X
- (defun math-pow-zero (a b)
- X (if (eq (car-safe a) 'mod)
- X (math-make-mod 1 (nth 2 a))
- X (if (math-known-matrixp a)
- X (math-mimic-ident 1 a)
- X (if (math-infinitep a)
- X '(var nan var-nan)
- X (if (and (eq (car a) 'intv) (math-intv-constp a)
- X (or (and (not (math-posp a)) (not (math-negp a)))
- X (not (math-intv-constp a t))))
- X '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
- X (if (or (math-floatp a) (math-floatp b))
- X '(float 1 0) 1)))))
- )
- X
- (defun math-pow-fancy (a b)
- X (cond ((and (Math-numberp a) (Math-numberp b))
- X (or (if (memq (math-quarter-integer b) '(1 2 3))
- X (let ((sqrt (math-sqrt (if (math-floatp b)
- X (math-float a) a))))
- X (and (Math-numberp sqrt)
- X (math-pow sqrt (math-mul 2 b))))
- X (and (eq (car b) 'frac)
- X (integerp (nth 2 b))
- X (<= (nth 2 b) 10)
- X (let ((root (math-nth-root a (nth 2 b))))
- X (and root (math-ipow root (nth 1 b))))))
- X (and (or (eq a 10) (equal a '(float 1 1)))
- X (math-num-integerp b)
- X (calcFunc-scf '(float 1 0) b))
- X (and calc-symbolic-mode
- X (list '^ a b))
- X (math-with-extra-prec 2
- X (math-exp-raw
- X (math-float (math-mul b (math-ln-raw (math-float a))))))))
- X ((or (not (Math-objvecp a))
- X (not (Math-objectp b)))
- X (let (temp)
- X (cond ((and math-simplify-only
- X (not (equal a math-simplify-only)))
- X (list '^ a b))
- X ((and (eq (car-safe a) '*)
- X (or (math-known-num-integerp b)
- X (math-known-nonnegp (nth 1 a))
- X (math-known-nonnegp (nth 2 a))))
- X (math-mul (math-pow (nth 1 a) b)
- X (math-pow (nth 2 a) b)))
- X ((and (eq (car-safe a) '/)
- X (or (math-known-num-integerp b)
- X (math-known-nonnegp (nth 2 a))))
- X (math-div (math-pow (nth 1 a) b)
- X (math-pow (nth 2 a) b)))
- X ((and (eq (car-safe a) '/)
- X (math-known-nonnegp (nth 1 a))
- X (not (math-equal-int (nth 1 a) 1)))
- X (math-mul (math-pow (nth 1 a) b)
- X (math-pow (math-div 1 (nth 2 a)) b)))
- X ((and (eq (car-safe a) '^)
- X (or (math-known-num-integerp b)
- X (math-known-nonnegp (nth 1 a))))
- X (math-pow (nth 1 a) (math-mul (nth 2 a) b)))
- X ((and (eq (car-safe a) 'calcFunc-sqrt)
- X (or (math-known-num-integerp b)
- X (math-known-nonnegp (nth 1 a))))
- X (math-pow (nth 1 a) (math-div b 2)))
- X ((and (eq (car-safe a) '^)
- X (math-known-evenp (nth 2 a))
- X (memq (math-quarter-integer b) '(1 2 3))
- X (math-known-realp (nth 1 a)))
- X (math-abs (math-pow (nth 1 a) (math-mul (nth 2 a) b))))
- X ((and (math-looks-negp a)
- X (math-known-integerp b)
- X (setq temp (or (and (math-known-evenp b)
- X (math-pow (math-neg a) b))
- X (and (math-known-oddp b)
- X (math-neg (math-pow (math-neg a)
- X b))))))
- X temp)
- X ((and (eq (car-safe a) 'calcFunc-abs)
- X (math-known-realp (nth 1 a))
- X (math-known-evenp b))
- X (math-pow (nth 1 a) b))
- X ((math-infinitep a)
- X (cond ((equal a '(var nan var-nan))
- X a)
- X ((eq (car a) 'neg)
- X (math-mul (math-pow -1 b) (math-pow (nth 1 a) b)))
- X ((math-posp b)
- X a)
- X ((math-negp b)
- X (if (math-floatp b) '(float 0 0) 0))
- X ((and (eq (car-safe b) 'intv)
- X (math-intv-constp b))
- X '(intv 3 0 (var inf var-inf)))
- X (t
- X '(var nan var-nan))))
- X ((math-infinitep b)
- X (let (scale)
- X (cond ((math-negp b)
- X (math-pow (math-div 1 a) (math-neg b)))
- X ((not (math-posp b))
- X '(var nan var-nan))
- X ((math-equal-int (setq scale (calcFunc-abssqr a)) 1)
- X '(var nan var-nan))
- X ((Math-lessp scale 1)
- X (if (math-floatp a) '(float 0 0) 0))
- X ((Math-lessp 1 a)
- X b)
- X ((Math-lessp a -1)
- X '(var uinf var-uinf))
- X ((and (eq (car a) 'intv)
- X (math-intv-constp a))
- X (if (Math-lessp -1 a)
- X (if (math-equal-int (nth 3 a) 1)
- X '(intv 3 0 1)
- X '(intv 3 0 (var inf var-inf)))
- X '(intv 3 (neg (var inf var-inf))
- X (var inf var-inf))))
- X (t (list '^ a b)))))
- X ((and (eq (car-safe a) 'calcFunc-idn)
- X (= (length a) 2)
- X (math-known-num-integerp b))
- X (list 'calcFunc-idn (math-pow (nth 1 a) b)))
- X (t (if (Math-objectp a)
- X (calc-record-why 'objectp b)
- X (calc-record-why 'objectp a))
- X (list '^ a b)))))
- X ((and (eq (car-safe a) 'sdev) (eq (car-safe b) 'sdev))
- X (if (and (math-constp a) (math-constp b))
- X (math-with-extra-prec 2
- X (let* ((ln (math-ln-raw (math-float (nth 1 a))))
- X (pow (math-exp-raw
- X (math-float (math-mul (nth 1 b) ln)))))
- X (math-make-sdev
- X pow
- X (math-mul
- X pow
- X (math-hypot (math-mul (nth 2 a)
- X (math-div (nth 1 b) (nth 1 a)))
- X (math-mul (nth 2 b) ln))))))
- X (let ((pow (math-pow (nth 1 a) (nth 1 b))))
- X (math-make-sdev
- X pow
- X (math-mul pow
- X (math-hypot (math-mul (nth 2 a)
- X (math-div (nth 1 b) (nth 1 a)))
- X (math-mul (nth 2 b) (calcFunc-ln
- X (nth 1 a)))))))))
- X ((and (eq (car-safe a) 'sdev) (Math-numberp b))
- X (if (math-constp a)
- X (math-with-extra-prec 2
- X (let ((pow (math-pow (nth 1 a) (math-sub b 1))))
- X (math-make-sdev (math-mul pow (nth 1 a))
- X (math-mul pow (math-mul (nth 2 a) b)))))
- X (math-make-sdev (math-pow (nth 1 a) b)
- X (math-mul (math-pow (nth 1 a) (math-add b -1))
- X (math-mul (nth 2 a) b)))))
- X ((and (eq (car-safe b) 'sdev) (Math-numberp a))
- X (math-with-extra-prec 2
- X (let* ((ln (math-ln-raw (math-float a)))
- X (pow (calcFunc-exp (math-mul (nth 1 b) ln))))
- X (math-make-sdev pow (math-mul pow (math-mul (nth 2 b) ln))))))
- X ((and (eq (car-safe a) 'intv) (math-intv-constp a)
- X (Math-realp b)
- X (or (Math-natnump b)
- X (Math-posp (nth 2 a))
- X (and (math-zerop (nth 2 a))
- X (or (Math-posp b)
- X (and (Math-integerp b) calc-infinite-mode)))
- X (Math-negp (nth 3 a))
- X (and (math-zerop (nth 3 a))
- X (or (Math-posp b)
- X (and (Math-integerp b) calc-infinite-mode)))))
- X (if (math-evenp b)
- X (setq a (math-abs a)))
- X (let ((calc-infinite-mode (if (math-zerop (nth 3 a)) -1 1)))
- X (math-sort-intv (nth 1 a)
- X (math-pow (nth 2 a) b)
- X (math-pow (nth 3 a) b))))
- X ((and (eq (car-safe b) 'intv) (math-intv-constp b)
- X (Math-realp a) (Math-posp a))
- X (math-sort-intv (nth 1 b)
- X (math-pow a (nth 2 b))
- X (math-pow a (nth 3 b))))
- X ((and (eq (car-safe a) 'intv) (math-intv-constp a)
- X (eq (car-safe b) 'intv) (math-intv-constp b)
- X (or (and (not (Math-negp (nth 2 a)))
- X (not (Math-negp (nth 2 b))))
- X (and (Math-posp (nth 2 a))
- X (not (Math-posp (nth 3 b))))))
- X (let ((lo (math-pow a (nth 2 b)))
- X (hi (math-pow a (nth 3 b))))
- X (or (eq (car-safe lo) 'intv)
- X (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) lo lo)))
- X (or (eq (car-safe hi) 'intv)
- X (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) hi hi)))
- X (math-combine-intervals
- X (nth 2 lo) (and (or (memq (nth 1 b) '(2 3))
- X (math-infinitep (nth 2 lo)))
- X (memq (nth 1 lo) '(2 3)))
- X (nth 3 lo) (and (or (memq (nth 1 b) '(2 3))
- X (math-infinitep (nth 3 lo)))
- X (memq (nth 1 lo) '(1 3)))
- X (nth 2 hi) (and (or (memq (nth 1 b) '(1 3))
- X (math-infinitep (nth 2 hi)))
- X (memq (nth 1 hi) '(2 3)))
- X (nth 3 hi) (and (or (memq (nth 1 b) '(1 3))
- X (math-infinitep (nth 3 hi)))
- X (memq (nth 1 hi) '(1 3))))))
- X ((and (eq (car-safe a) 'mod) (eq (car-safe b) 'mod)
- X (equal (nth 2 a) (nth 2 b)))
- X (math-make-mod (math-pow-mod (nth 1 a) (nth 1 b) (nth 2 a))
- X (nth 2 a)))
- X ((and (eq (car-safe a) 'mod) (Math-anglep b))
- X (math-make-mod (math-pow-mod (nth 1 a) b (nth 2 a)) (nth 2 a)))
- X ((and (eq (car-safe b) 'mod) (Math-anglep a))
- X (math-make-mod (math-pow-mod a (nth 1 b) (nth 2 b)) (nth 2 b)))
- X ((not (Math-numberp a))
- X (math-reject-arg a 'numberp))
- X (t
- X (math-reject-arg b 'numberp)))
- )
- X
- (defun math-quarter-integer (x)
- X (if (Math-integerp x)
- X 0
- X (if (math-negp x)
- X (progn
- X (setq x (math-quarter-integer (math-neg x)))
- X (and x (- 4 x)))
- X (if (eq (car x) 'frac)
- X (if (eq (nth 2 x) 2)
- X 2
- X (and (eq (nth 2 x) 4)
- X (progn
- X (setq x (nth 1 x))
- X (% (if (consp x) (nth 1 x) x) 4))))
- X (if (eq (car x) 'float)
- X (if (>= (nth 2 x) 0)
- X 0
- X (if (= (nth 2 x) -1)
- X (progn
- X (setq x (nth 1 x))
- X (and (= (% (if (consp x) (nth 1 x) x) 10) 5) 2))
- X (if (= (nth 2 x) -2)
- X (progn
- X (setq x (nth 1 x)
- X x (% (if (consp x) (nth 1 x) x) 100))
- X (if (= x 25) 1
- X (if (= x 75) 3))))))))))
- )
- X
- ;;; This assumes A < M and M > 0.
- (defun math-pow-mod (a b m) ; [R R R R]
- X (if (and (Math-integerp a) (Math-integerp b) (Math-integerp m))
- X (if (Math-negp b)
- X (math-div-mod 1 (math-pow-mod a (Math-integer-neg b) m) m)
- X (if (eq m 1)
- X 0
- X (math-pow-mod-step a b m)))
- X (math-mod (math-pow a b) m))
- )
- X
- (defun math-pow-mod-step (a n m) ; [I I I I]
- X (math-working "pow" a)
- X (let ((val (cond
- X ((eq n 0) 1)
- X ((eq n 1) a)
- X (t
- X (let ((rest (math-pow-mod-step
- X (math-imod (math-mul a a) m)
- X (math-div2 n)
- X m)))
- X (if (math-evenp n)
- X rest
- X (math-mod (math-mul a rest) m)))))))
- X (math-working "pow" val)
- X val)
- )
- X
- X
- ;;; Compute the minimum of two real numbers. [R R R] [Public]
- (defun math-min (a b)
- X (if (and (consp a) (eq (car a) 'intv))
- X (if (and (consp b) (eq (car b) 'intv))
- X (let ((lo (nth 2 a))
- X (lom (memq (nth 1 a) '(2 3)))
- X (hi (nth 3 a))
- X (him (memq (nth 1 a) '(1 3)))
- X res)
- X (if (= (setq res (math-compare (nth 2 b) lo)) -1)
- X (setq lo (nth 2 b) lom (memq (nth 1 b) '(2 3)))
- X (if (= res 0)
- X (setq lom (or lom (memq (nth 1 b) '(2 3))))))
- X (if (= (setq res (math-compare (nth 3 b) hi)) -1)
- X (setq hi (nth 3 b) him (memq (nth 1 b) '(1 3)))
- X (if (= res 0)
- X (setq him (or him (memq (nth 1 b) '(1 3))))))
- X (math-make-intv (+ (if lom 2 0) (if him 1 0)) lo hi))
- X (math-min a (list 'intv 3 b b)))
- X (if (and (consp b) (eq (car b) 'intv))
- X (math-min (list 'intv 3 a a) b)
- X (let ((res (math-compare a b)))
- X (if (= res 1)
- X b
- X (if (= res 2)
- X '(var nan var-nan)
- X a)))))
- )
- X
- (defun calcFunc-min (&optional a &rest b)
- X (if (not a)
- X '(var inf var-inf)
- X (if (not (or (Math-anglep a) (eq (car a) 'date)
- X (and (eq (car a) 'intv) (math-intv-constp a))
- X (math-infinitep a)))
- X (math-reject-arg a 'anglep))
- X (math-min-list a b))
- )
- X
- (defun math-min-list (a b)
- X (if b
- X (if (or (Math-anglep (car b)) (eq (car b) 'date)
- X (and (eq (car (car b)) 'intv) (math-intv-constp (car b)))
- X (math-infinitep (car b)))
- X (math-min-list (math-min a (car b)) (cdr b))
- X (math-reject-arg (car b) 'anglep))
- X a)
- )
- X
- ;;; Compute the maximum of two real numbers. [R R R] [Public]
- (defun math-max (a b)
- X (if (or (and (consp a) (eq (car a) 'intv))
- X (and (consp b) (eq (car b) 'intv)))
- X (math-neg (math-min (math-neg a) (math-neg b)))
- X (let ((res (math-compare a b)))
- X (if (= res -1)
- X b
- X (if (= res 2)
- X '(var nan var-nan)
- X a))))
- )
- X
- (defun calcFunc-max (&optional a &rest b)
- X (if (not a)
- X '(neg (var inf var-inf))
- X (if (not (or (Math-anglep a) (eq (car a) 'date)
- X (and (eq (car a) 'intv) (math-intv-constp a))
- X (math-infinitep a)))
- X (math-reject-arg a 'anglep))
- X (math-max-list a b))
- )
- X
- (defun math-max-list (a b)
- X (if b
- X (if (or (Math-anglep (car b)) (eq (car b) 'date)
- X (and (eq (car (car b)) 'intv) (math-intv-constp (car b)))
- X (math-infinitep (car b)))
- X (math-max-list (math-max a (car b)) (cdr b))
- X (math-reject-arg (car b) 'anglep))
- X a)
- )
- X
- X
- ;;; Compute the absolute value of A. [O O; r r] [Public]
- (defun math-abs (a)
- X (cond ((Math-negp a)
- X (math-neg a))
- X ((Math-anglep a)
- X a)
- X ((eq (car a) 'cplx)
- X (math-hypot (nth 1 a) (nth 2 a)))
- X ((eq (car a) 'polar)
- X (nth 1 a))
- X ((eq (car a) 'vec)
- X (if (cdr (cdr (cdr a)))
- X (math-sqrt (calcFunc-abssqr a))
- X (if (cdr (cdr a))
- X (math-hypot (nth 1 a) (nth 2 a))
- X (if (cdr a)
- X (math-abs (nth 1 a))
- X a))))
- X ((eq (car a) 'sdev)
- X (list 'sdev (math-abs (nth 1 a)) (nth 2 a)))
- X ((and (eq (car a) 'intv) (math-intv-constp a))
- X (if (Math-posp a)
- X a
- X (let* ((nlo (math-neg (nth 2 a)))
- X (res (math-compare nlo (nth 3 a))))
- X (cond ((= res 1)
- X (math-make-intv (if (memq (nth 1 a) '(0 1)) 2 3) 0 nlo))
- X ((= res 0)
- X (math-make-intv (if (eq (nth 1 a) 0) 2 3) 0 nlo))
- X (t
- X (math-make-intv (if (memq (nth 1 a) '(0 2)) 2 3)
- X 0 (nth 3 a)))))))
- X ((math-looks-negp a)
- X (list 'calcFunc-abs (math-neg a)))
- X ((let ((signs (math-possible-signs a)))
- X (or (and (memq signs '(2 4 6)) a)
- X (and (memq signs '(1 3)) (math-neg a)))))
- X ((let ((inf (math-infinitep a)))
- X (and inf
- X (if (equal inf '(var nan var-nan))
- X inf
- X '(var inf var-inf)))))
- X (t (calc-record-why 'numvecp a)
- X (list 'calcFunc-abs a)))
- )
- (fset 'calcFunc-abs (symbol-function 'math-abs))
- X
- X
- (defun math-float-fancy (a)
- X (cond ((eq (car a) 'intv)
- X (cons (car a) (cons (nth 1 a) (mapcar 'math-float (nthcdr 2 a)))))
- X ((and (memq (car a) '(* /))
- X (math-numberp (nth 1 a)))
- X (list (car a) (math-float (nth 1 a))
- X (list 'calcFunc-float (nth 2 a))))
- X ((and (eq (car a) '/)
- X (eq (car (nth 1 a)) '*)
- X (math-numberp (nth 1 (nth 1 a))))
- X (list '* (math-float (nth 1 (nth 1 a)))
- X (list 'calcFunc-float (list '/ (nth 2 (nth 1 a)) (nth 2 a)))))
- X ((math-infinitep a) a)
- X ((eq (car a) 'calcFunc-float) a)
- X ((let ((func (assq (car a) '((calcFunc-floor . calcFunc-ffloor)
- X (calcFunc-ceil . calcFunc-fceil)
- X (calcFunc-trunc . calcFunc-ftrunc)
- X (calcFunc-round . calcFunc-fround)
- X (calcFunc-rounde . calcFunc-frounde)
- X (calcFunc-roundu . calcFunc-froundu)))))
- X (and func (cons (cdr func) (cdr a)))))
- X (t (math-reject-arg a 'objectp)))
- )
- (fset 'calcFunc-float (symbol-function 'math-float))
- X
- X
- (defun math-trunc-fancy (a)
- X (cond ((eq (car a) 'frac) (math-quotient (nth 1 a) (nth 2 a)))
- X ((eq (car a) 'cplx) (math-trunc (nth 1 a)))
- X ((eq (car a) 'polar) (math-trunc (math-complex a)))
- X ((eq (car a) 'hms) (list 'hms (nth 1 a) 0 0))
- X ((eq (car a) 'date) (list 'date (math-trunc (nth 1 a))))
- X ((eq (car a) 'mod)
- X (if (math-messy-integerp (nth 2 a))
- X (math-trunc (math-make-mod (nth 1 a) (math-trunc (nth 2 a))))
- X (math-make-mod (math-trunc (nth 1 a)) (nth 2 a))))
- X ((eq (car a) 'intv)
- X (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
- X (memq (nth 1 a) '(0 1)))
- X 0 2)
- X (if (and (equal (nth 3 a) '(var inf var-inf))
- X (memq (nth 1 a) '(0 2)))
- X 0 1))
- X (if (and (Math-negp (nth 2 a))
- X (Math-num-integerp (nth 2 a))
- X (memq (nth 1 a) '(0 1)))
- X (math-add (math-trunc (nth 2 a)) 1)
- X (math-trunc (nth 2 a)))
- X (if (and (Math-posp (nth 3 a))
- X (Math-num-integerp (nth 3 a))
- X (memq (nth 1 a) '(0 2)))
- X (math-add (math-trunc (nth 3 a)) -1)
- X (math-trunc (nth 3 a)))))
- X ((math-provably-integerp a) a)
- X ((Math-vectorp a)
- X (math-map-vec (function (lambda (x) (math-trunc x prec))) a))
- X ((math-infinitep a)
- X (if (or (math-posp a) (math-negp a))
- X a
- X '(var nan var-nan)))
- X ((math-to-integer a))
- X (t (math-reject-arg a 'numberp)))
- )
- X
- (defun math-trunc-special (a prec)
- X (if (Math-messy-integerp prec)
- X (setq prec (math-trunc prec)))
- X (or (integerp prec)
- X (math-reject-arg prec 'fixnump))
- X (if (and (<= prec 0)
- X (math-provably-integerp a))
- X a
- X (calcFunc-scf (math-trunc (let ((calc-prefer-frac t))
- X (calcFunc-scf a prec)))
- X (- prec)))
- )
- X
- (defun math-to-integer (a)
- X (let ((func (assq (car-safe a) '((calcFunc-ffloor . calcFunc-floor)
- X (calcFunc-fceil . calcFunc-ceil)
- X (calcFunc-ftrunc . calcFunc-trunc)
- X (calcFunc-fround . calcFunc-round)
- X (calcFunc-frounde . calcFunc-rounde)
- X (calcFunc-froundu . calcFunc-roundu)))))
- X (and func (= (length a) 2)
- X (cons (cdr func) (cdr a))))
- )
- X
- (defun calcFunc-ftrunc (a &optional prec)
- X (if (and (Math-messy-integerp a)
- X (or (not prec) (and (integerp prec)
- X (<= prec 0))))
- X a
- X (math-float (math-trunc a prec)))
- )
- X
- (defun math-floor-fancy (a)
- X (cond ((math-provably-integerp a) a)
- X ((eq (car a) 'hms)
- X (if (or (math-posp a)
- X (and (math-zerop (nth 2 a))
- X (math-zerop (nth 3 a))))
- X (math-trunc a)
- X (math-add (math-trunc a) -1)))
- X ((eq (car a) 'date) (list 'date (math-floor (nth 1 a))))
- X ((eq (car a) 'intv)
- X (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
- X (memq (nth 1 a) '(0 1)))
- X 0 2)
- X (if (and (equal (nth 3 a) '(var inf var-inf))
- X (memq (nth 1 a) '(0 2)))
- X 0 1))
- X (math-floor (nth 2 a))
- X (if (and (Math-num-integerp (nth 3 a))
- X (memq (nth 1 a) '(0 2)))
- X (math-add (math-floor (nth 3 a)) -1)
- X (math-floor (nth 3 a)))))
- X ((Math-vectorp a)
- X (math-map-vec (function (lambda (x) (math-floor x prec))) a))
- X ((math-infinitep a)
- X (if (or (math-posp a) (math-negp a))
- X a
- X '(var nan var-nan)))
- X ((math-to-integer a))
- X (t (math-reject-arg a 'anglep)))
- )
- X
- (defun math-floor-special (a prec)
- X (if (Math-messy-integerp prec)
- X (setq prec (math-trunc prec)))
- X (or (integerp prec)
- X (math-reject-arg prec 'fixnump))
- X (if (and (<= prec 0)
- X (math-provably-integerp a))
- X a
- X (calcFunc-scf (math-floor (let ((calc-prefer-frac t))
- X (calcFunc-scf a prec)))
- X (- prec)))
- )
- X
- (defun calcFunc-ffloor (a &optional prec)
- X (if (and (Math-messy-integerp a)
- X (or (not prec) (and (integerp prec)
- X (<= prec 0))))
- X a
- X (math-float (math-floor a prec)))
- )
- X
- ;;; Coerce A to be an integer (by truncation toward plus infinity). [I N]
- (defun math-ceiling (a &optional prec) ; [Public]
- X (cond (prec
- X (if (Math-messy-integerp prec)
- X (setq prec (math-trunc prec)))
- X (or (integerp prec)
- X (math-reject-arg prec 'fixnump))
- X (if (and (<= prec 0)
- X (math-provably-integerp a))
- X a
- X (calcFunc-scf (math-ceiling (let ((calc-prefer-frac t))
- X (calcFunc-scf a prec)))
- X (- prec))))
- X ((Math-integerp a) a)
- X ((Math-messy-integerp a) (math-trunc a))
- X ((Math-realp a)
- X (if (Math-posp a)
- X (math-add (math-trunc a) 1)
- X (math-trunc a)))
- X ((math-provably-integerp a) a)
- X ((eq (car a) 'hms)
- X (if (or (math-negp a)
- X (and (math-zerop (nth 2 a))
- X (math-zerop (nth 3 a))))
- X (math-trunc a)
- X (math-add (math-trunc a) 1)))
- X ((eq (car a) 'date) (list 'date (math-ceiling (nth 1 a))))
- X ((eq (car a) 'intv)
- X (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
- X (memq (nth 1 a) '(0 1)))
- X 0 2)
- X (if (and (equal (nth 3 a) '(var inf var-inf))
- X (memq (nth 1 a) '(0 2)))
- X 0 1))
- X (if (and (Math-num-integerp (nth 2 a))
- X (memq (nth 1 a) '(0 1)))
- X (math-add (math-floor (nth 2 a)) 1)
- X (math-ceiling (nth 2 a)))
- X (math-ceiling (nth 3 a))))
- X ((Math-vectorp a)
- X (math-map-vec (function (lambda (x) (math-ceiling x prec))) a))
- X ((math-infinitep a)
- X (if (or (math-posp a) (math-negp a))
- X a
- X '(var nan var-nan)))
- X ((math-to-integer a))
- X (t (math-reject-arg a 'anglep)))
- )
- (fset 'calcFunc-ceil (symbol-function 'math-ceiling))
- X
- (defun calcFunc-fceil (a &optional prec)
- X (if (and (Math-messy-integerp a)
- X (or (not prec) (and (integerp prec)
- X (<= prec 0))))
- X a
- X (math-float (math-ceiling a prec)))
- )
- X
- (setq math-rounding-mode nil)
- X
- ;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public]
- (defun math-round (a &optional prec)
- X (cond (prec
- X (if (Math-messy-integerp prec)
- X (setq prec (math-trunc prec)))
- X (or (integerp prec)
- X (math-reject-arg prec 'fixnump))
- X (if (and (<= prec 0)
- X (math-provably-integerp a))
- X a
- X (calcFunc-scf (math-round (let ((calc-prefer-frac t))
- X (calcFunc-scf a prec)))
- X (- prec))))
- X ((Math-anglep a)
- X (if (Math-num-integerp a)
- X (math-trunc a)
- X (if (and (Math-negp a) (not (eq math-rounding-mode 'up)))
- X (math-neg (math-round (math-neg a)))
- X (setq a (let ((calc-angle-mode 'deg)) ; in case of HMS forms
- X (math-add a (if (Math-ratp a)
- X '(frac 1 2)
- X '(float 5 -1)))))
- X (if (and (Math-num-integerp a) (eq math-rounding-mode 'even))
- X (progn
- X (setq a (math-floor a))
- X (or (math-evenp a)
- X (setq a (math-sub a 1)))
- X a)
- X (math-floor a)))))
- X ((math-provably-integerp a) a)
- X ((eq (car a) 'date) (list 'date (math-round (nth 1 a))))
- X ((eq (car a) 'intv)
- X (math-floor (math-add a '(frac 1 2))))
- X ((Math-vectorp a)
- X (math-map-vec (function (lambda (x) (math-round x prec))) a))
- X ((math-infinitep a)
- X (if (or (math-posp a) (math-negp a))
- X a
- X '(var nan var-nan)))
- X ((math-to-integer a))
- X (t (math-reject-arg a 'anglep)))
- )
- (fset 'calcFunc-round (symbol-function 'math-round))
- X
- (defun calcFunc-rounde (a &optional prec)
- X (let ((math-rounding-mode 'even))
- X (math-round a prec))
- )
- X
- (defun calcFunc-roundu (a &optional prec)
- X (let ((math-rounding-mode 'up))
- X (math-round a prec))
- )
- X
- (defun calcFunc-fround (a &optional prec)
- X (if (and (Math-messy-integerp a)
- X (or (not prec) (and (integerp prec)
- X (<= prec 0))))
- X a
- X (math-float (math-round a prec)))
- )
- X
- (defun calcFunc-frounde (a &optional prec)
- X (let ((math-rounding-mode 'even))
- X (calcFunc-fround a prec))
- )
- X
- (defun calcFunc-froundu (a &optional prec)
- X (let ((math-rounding-mode 'up))
- X (calcFunc-fround a prec))
- )
- X
- X
- ;;; Pull floating-point values apart into mantissa and exponent.
- (defun calcFunc-mant (x)
- X (if (Math-realp x)
- X (if (or (Math-ratp x)
- X (eq (nth 1 x) 0))
- X x
- X (list 'float (nth 1 x) (- 1 (math-numdigs (nth 1 x)))))
- X (calc-record-why 'realp x)
- X (list 'calcFunc-mant x))
- )
- X
- (defun calcFunc-xpon (x)
- X (if (Math-realp x)
- X (if (or (Math-ratp x)
- X (eq (nth 1 x) 0))
- X 0
- X (math-normalize (+ (nth 2 x) (1- (math-numdigs (nth 1 x))))))
- X (calc-record-why 'realp x)
- X (list 'calcFunc-xpon x))
- )
- X
- (defun calcFunc-scf (x n)
- X (if (integerp n)
- X (cond ((eq n 0)
- X x)
- X ((Math-integerp x)
- X (if (> n 0)
- X (math-scale-int x n)
- X (math-div x (math-scale-int 1 (- n)))))
- X ((eq (car x) 'frac)
- X (if (> n 0)
- X (math-make-frac (math-scale-int (nth 1 x) n) (nth 2 x))
- X (math-make-frac (nth 1 x) (math-scale-int (nth 2 x) (- n)))))
- X ((eq (car x) 'float)
- X (math-make-float (nth 1 x) (+ (nth 2 x) n)))
- X ((memq (car x) '(cplx sdev))
- X (math-normalize
- X (list (car x)
- X (calcFunc-scf (nth 1 x) n)
- X (calcFunc-scf (nth 2 x) n))))
- X ((memq (car x) '(polar mod))
- X (math-normalize
- X (list (car x)
- X (calcFunc-scf (nth 1 x) n)
- X (nth 2 x))))
- X ((eq (car x) 'intv)
- X (math-normalize
- X (list (car x)
- X (nth 1 x)
- X (calcFunc-scf (nth 2 x) n)
- X (calcFunc-scf (nth 3 x) n))))
- X ((eq (car x) 'vec)
- X (math-map-vec (function (lambda (x) (calcFunc-scf x n))) x))
- X ((math-infinitep x)
- X x)
- X (t
- X (calc-record-why 'realp x)
- X (list 'calcFunc-scf x n)))
- X (if (math-messy-integerp n)
- X (if (< (nth 2 n) 10)
- X (calcFunc-scf x (math-trunc n))
- X (math-overflow n))
- X (if (math-integerp n)
- X (math-overflow n)
- X (calc-record-why 'integerp n)
- X (list 'calcFunc-scf x n))))
- )
- X
- X
- (defun calcFunc-incr (x &optional step relative-to)
- X (or step (setq step 1))
- X (cond ((not (Math-integerp step))
- X (math-reject-arg step 'integerp))
- X ((Math-integerp x)
- X (math-add x step))
- X ((eq (car x) 'float)
- X (if (and (math-zerop x)
- X (eq (car-safe relative-to) 'float))
- X (math-mul step
- X (calcFunc-scf relative-to (- 1 calc-internal-prec)))
- X (math-add-float x (math-make-float
- X step
- X (+ (nth 2 x)
- X (- (math-numdigs (nth 1 x))
- X calc-internal-prec))))))
- X ((eq (car x) 'date)
- X (if (Math-integerp (nth 1 x))
- X (math-add x step)
- X (math-add x (list 'hms 0 0 step))))
- X (t
- X (math-reject-arg x 'realp)))
- )
- X
- (defun calcFunc-decr (x &optional step relative-to)
- X (calcFunc-incr x (math-neg (or step 1)) relative-to)
- )
- X
- X
- (defun calcFunc-percent (x)
- X (if (math-objectp x)
- X (math-mul x '(float 1 -2))
- X (list 'calcFunc-percent x))
- )
- X
- X
- X
- ;;; Compute the absolute value squared of A. [F N] [Public]
- (defun calcFunc-abssqr (a)
- X (cond ((Math-realp a)
- X (math-mul a a))
- X ((eq (car a) 'cplx)
- X (math-add (math-sqr (nth 1 a))
- X (math-sqr (nth 2 a))))
- X ((eq (car a) 'polar)
- X (math-sqr (nth 1 a)))
- X ((and (memq (car a) '(sdev intv)) (math-constp a))
- X (math-sqr (math-abs a)))
- X ((eq (car a) 'vec)
- X (math-reduce-vec 'math-add (math-map-vec 'calcFunc-abssqr a)))
- X ((math-known-realp a)
- X (math-pow a 2))
- X ((let ((inf (math-infinitep a)))
- X (and inf
- X (math-mul (calcFunc-abssqr (math-infinite-dir a inf)) inf))))
- X (t (calc-record-why 'numvecp a)
- X (list 'calcFunc-abssqr a)))
- )
- (defun math-sqr (a)
- X (math-mul a a)
- )
- X
- X
- ;;;; Number theory.
- X
- (defun calcFunc-idiv (a b) ; [I I I] [Public]
- X (cond ((and (Math-natnump a) (Math-natnump b) (not (eq b 0)))
- X (math-quotient a b))
- X ((Math-realp a)
- X (if (Math-realp b)
- X (let ((calc-prefer-frac t))
- X (math-floor (math-div a b)))
- X (math-reject-arg b 'realp)))
- X ((eq (car-safe a) 'hms)
- X (if (eq (car-safe b) 'hms)
- X (let ((calc-prefer-frac t))
- X (math-floor (math-div a b)))
- X (math-reject-arg b 'hmsp)))
- X ((and (or (eq (car-safe a) 'intv) (Math-realp a))
- X (or (eq (car-safe b) 'intv) (Math-realp b)))
- X (math-floor (math-div a b)))
- X ((or (math-infinitep a)
- X (math-infinitep b))
- X (math-div a b))
- X (t (math-reject-arg a 'anglep)))
- )
- X
- X
- ;;; Combine two terms being added, if possible.
- (defun math-combine-sum (a b nega negb scalar-okay)
- X (if (and scalar-okay (Math-objvecp a) (Math-objvecp b))
- X (math-add-or-sub a b nega negb)
- X (let ((amult 1) (bmult 1))
- X (and (consp a)
- X (cond ((and (eq (car a) '*)
- X (Math-objectp (nth 1 a)))
- X (setq amult (nth 1 a)
- X a (nth 2 a)))
- X ((and (eq (car a) '/)
- X (Math-objectp (nth 2 a)))
- X (setq amult (if (Math-integerp (nth 2 a))
- X (list 'frac 1 (nth 2 a))
- X (math-div 1 (nth 2 a)))
- X a (nth 1 a)))
- X ((eq (car a) 'neg)
- X (setq amult -1
- X a (nth 1 a)))))
- X (and (consp b)
- X (cond ((and (eq (car b) '*)
- X (Math-objectp (nth 1 b)))
- X (setq bmult (nth 1 b)
- X b (nth 2 b)))
- X ((and (eq (car b) '/)
- X (Math-objectp (nth 2 b)))
- X (setq bmult (if (Math-integerp (nth 2 b))
- X (list 'frac 1 (nth 2 b))
- X (math-div 1 (nth 2 b)))
- X b (nth 1 b)))
- X ((eq (car b) 'neg)
- X (setq bmult -1
- X b (nth 1 b)))))
- X (and (if math-simplifying
- X (Math-equal a b)
- X (equal a b))
- X (progn
- X (if nega (setq amult (math-neg amult)))
- X (if negb (setq bmult (math-neg bmult)))
- X (setq amult (math-add amult bmult))
- X (math-mul amult a)))))
- )
- X
- (defun math-add-or-sub (a b aneg bneg)
- X (if aneg (setq a (math-neg a)))
- X (if bneg (setq b (math-neg b)))
- X (if (or (Math-vectorp a) (Math-vectorp b))
- X (math-normalize (list '+ a b))
- X (math-add a b))
- )
- X
- ;;; The following is expanded out four ways for speed.
- (defun math-combine-prod (a b inva invb scalar-okay)
- X (cond
- X ((or (and inva (Math-zerop a))
- X (and invb (Math-zerop b)))
- X nil)
- X ((and scalar-okay (Math-objvecp a) (Math-objvecp b))
- X (setq a (math-mul-or-div a b inva invb))
- X (and (Math-objvecp a)
- X a))
- X ((and (eq (car-safe a) '^)
- X inva
- X (math-looks-negp (nth 2 a)))
- X (math-mul (math-pow (nth 1 a) (math-neg (nth 2 a))) b))
- X ((and (eq (car-safe b) '^)
- X invb
- X (math-looks-negp (nth 2 b)))
- X (math-mul a (math-pow (nth 1 b) (math-neg (nth 2 b)))))
- X (t (let ((apow 1) (bpow 1))
- X (and (consp a)
- X (cond ((and (eq (car a) '^)
- X (or math-simplifying
- X (Math-numberp (nth 2 a))))
- X (setq apow (nth 2 a)
- X a (nth 1 a)))
- X ((eq (car a) 'calcFunc-sqrt)
- X (setq apow '(frac 1 2)
- X a (nth 1 a)))
- X ((and (eq (car a) 'calcFunc-exp)
- X (or math-simplifying
- X (Math-numberp (nth 1 a))))
- X (setq apow (nth 1 a)
- X a math-combine-prod-e))))
- X (and (consp a) (eq (car a) 'frac)
- X (Math-lessp (nth 1 a) (nth 2 a))
- X (setq a (math-div 1 a) apow (math-neg apow)))
- X (and (consp b)
- X (cond ((and (eq (car b) '^)
- X (or math-simplifying
- X (Math-numberp (nth 2 b))))
- X (setq bpow (nth 2 b)
- X b (nth 1 b)))
- X ((eq (car b) 'calcFunc-sqrt)
- X (setq bpow '(frac 1 2)
- X b (nth 1 b)))
- X ((and (eq (car b) 'calcFunc-exp)
- X (or math-simplifying
- X (Math-numberp (nth 1 b))))
- X (setq bpow (nth 1 b)
- X b math-combine-prod-e))))
- X (and (consp b) (eq (car b) 'frac)
- X (Math-lessp (nth 1 b) (nth 2 b))
- X (setq b (math-div 1 b) bpow (math-neg bpow)))
- X (if inva (setq apow (math-neg apow)))
- X (if invb (setq bpow (math-neg bpow)))
- X (or (and (if math-simplifying
- X (math-commutative-equal a b)
- X (equal a b))
- X (let ((sumpow (math-add apow bpow)))
- X (and (or (not (Math-integerp a))
- X (Math-zerop sumpow)
- X (eq (eq (car-safe apow) 'frac)
- X (eq (car-safe bpow) 'frac)))
- X (progn
- X (and (math-looks-negp sumpow)
- X (Math-ratp a) (Math-posp a)
- X (setq a (math-div 1 a)
- X sumpow (math-neg sumpow)))
- X (cond ((equal sumpow '(frac 1 2))
- X (list 'calcFunc-sqrt a))
- X ((equal sumpow '(frac -1 2))
- X (math-div 1 (list 'calcFunc-sqrt a)))
- X ((and (eq a math-combine-prod-e)
- X (eq a b))
- X (list 'calcFunc-exp sumpow))
- X (t
- X (condition-case err
- X (math-pow a sumpow)
- X (inexact-result (list '^ a sumpow)))))))))
- X (and math-simplifying-units
- X math-combining-units
- X (let* ((ua (math-check-unit-name a))
- X ub)
- X (and ua
- X (eq ua (setq ub (math-check-unit-name b)))
- X (progn
- X (setq ua (if (eq (nth 1 a) (car ua))
- X 1
- X (nth 1 (assq (aref (symbol-name (nth 1 a))
- X 0)
- X math-unit-prefixes)))
- X ub (if (eq (nth 1 b) (car ub))
- X 1
- X (nth 1 (assq (aref (symbol-name (nth 1 b))
- X 0)
- X math-unit-prefixes))))
- X (if (Math-lessp ua ub)
- X (let (temp)
- X (setq temp a a b b temp
- X temp ua ua ub ub temp
- X temp apow apow bpow bpow temp)))
- X (math-mul (math-pow (math-div ua ub) apow)
- X (math-pow b (math-add apow bpow)))))))
- X (and (equal apow bpow)
- X (Math-natnump a) (Math-natnump b)
- X (cond ((equal apow '(frac 1 2))
- X (list 'calcFunc-sqrt (math-mul a b)))
- X ((equal apow '(frac -1 2))
- X (math-div 1 (list 'calcFunc-sqrt (math-mul a b))))
- X (t
- X (setq a (math-mul a b))
- X (condition-case err
- X (math-pow a apow)
- X (inexact-result (list '^ a apow))))))))))
- )
- (setq math-combine-prod-e '(var e var-e))
- X
- (defun math-mul-or-div (a b ainv binv)
- X (if (or (Math-vectorp a) (Math-vectorp b))
- X (math-normalize
- X (if ainv
- X (if binv
- X (list '/ (math-div 1 a) b)
- X (list '/ b a))
- X (if binv
- X (list '/ a b)
- X (list '* a b))))
- X (if ainv
- X (if binv
- X (math-div (math-div 1 a) b)
- X (math-div b a))
- X (if binv
- X (math-div a b)
- X (math-mul a b))))
- )
- X
- (defun math-commutative-equal (a b)
- X (if (memq (car-safe a) '(+ -))
- X (and (memq (car-safe b) '(+ -))
- X (let ((bterms nil) aterms p)
- X (math-commutative-collect b nil)
- X (setq aterms bterms bterms nil)
- X (math-commutative-collect a nil)
- X (and (= (length aterms) (length bterms))
- X (progn
- X (while (and aterms
- X (progn
- X (setq p bterms)
- X (while (and p (not (equal (car aterms)
- X (car p))))
- X (setq p (cdr p)))
- X p))
- X (setq bterms (delq (car p) bterms)
- X aterms (cdr aterms)))
- X (not aterms)))))
- X (equal a b))
- )
- X
- (defun math-commutative-collect (b neg)
- X (if (eq (car-safe b) '+)
- X (progn
- X (math-commutative-collect (nth 1 b) neg)
- X (math-commutative-collect (nth 2 b) neg))
- X (if (eq (car-safe b) '-)
- X (progn
- X (math-commutative-collect (nth 1 b) neg)
- X (math-commutative-collect (nth 2 b) (not neg)))
- X (setq bterms (cons (if neg (math-neg b) b) bterms))))
- )
- X
- X
- SHAR_EOF
- echo 'File calc-arith.el is complete' &&
- chmod 0644 calc-arith.el ||
- echo 'restore of calc-arith.el failed'
- Wc_c="`wc -c < 'calc-arith.el'`"
- test 86526 -eq "$Wc_c" ||
- echo 'calc-arith.el: original size 86526, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= calc-bin.el ==============
- if test -f 'calc-bin.el' -a X"$1" != X"-c"; then
- echo 'x - skipping calc-bin.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting calc-bin.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'calc-bin.el' &&
- ;; Calculator for GNU Emacs, part II [calc-bin.el]
- ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
- ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
- X
- ;; This file is part of GNU Emacs.
- X
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
- X
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
- X
- X
- X
- ;; This file is autoloaded from calc-ext.el.
- (require 'calc-ext)
- X
- (require 'calc-macs)
- X
- (defun calc-Need-calc-bin () nil)
- X
- X
- ;;; b-prefix binary commands.
- X
- (defun calc-and (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 2 "and"
- X (append '(calcFunc-and)
- X (calc-top-list-n 2)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-or (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 2 "or"
- X (append '(calcFunc-or)
- X (calc-top-list-n 2)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-xor (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 2 "xor"
- X (append '(calcFunc-xor)
- X (calc-top-list-n 2)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-diff (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 2 "diff"
- X (append '(calcFunc-diff)
- X (calc-top-list-n 2)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-not (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 1 "not"
- X (append '(calcFunc-not)
- X (calc-top-list-n 1)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-lshift-binary (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (let ((hyp (if (calc-is-hyperbolic) 2 1)))
- X (calc-enter-result hyp "lsh"
- X (append '(calcFunc-lsh)
- X (calc-top-list-n hyp)
- X (and n (list (prefix-numeric-value n)))))))
- )
- X
- (defun calc-rshift-binary (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (let ((hyp (if (calc-is-hyperbolic) 2 1)))
- X (calc-enter-result hyp "rsh"
- X (append '(calcFunc-rsh)
- X (calc-top-list-n hyp)
- X (and n (list (prefix-numeric-value n)))))))
- )
- X
- (defun calc-lshift-arith (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (let ((hyp (if (calc-is-hyperbolic) 2 1)))
- X (calc-enter-result hyp "ash"
- X (append '(calcFunc-ash)
- X (calc-top-list-n hyp)
- X (and n (list (prefix-numeric-value n)))))))
- )
- X
- (defun calc-rshift-arith (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (let ((hyp (if (calc-is-hyperbolic) 2 1)))
- X (calc-enter-result hyp "rash"
- X (append '(calcFunc-rash)
- X (calc-top-list-n hyp)
- X (and n (list (prefix-numeric-value n)))))))
- )
- X
- (defun calc-rotate-binary (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (let ((hyp (if (calc-is-hyperbolic) 2 1)))
- X (calc-enter-result hyp "rot"
- X (append '(calcFunc-rot)
- X (calc-top-list-n hyp)
- X (and n (list (prefix-numeric-value n)))))))
- )
- X
- (defun calc-clip (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 1 "clip"
- X (append '(calcFunc-clip)
- X (calc-top-list-n 1)
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-word-size (n)
- X (interactive "P")
- X (calc-wrapper
- X (or n (setq n (read-string (format "Binary word size: (default %d) "
- X calc-word-size))))
- X (setq n (if (stringp n)
- X (if (equal n "")
- X calc-word-size
- X (if (string-match "\\`[-+]?[0-9]+\\'" n)
- X (string-to-int n)
- X (error "Expected an integer")))
- X (prefix-numeric-value n)))
- X (or (= n calc-word-size)
- X (if (> (math-abs n) 100)
- X (calc-change-mode 'calc-word-size n calc-leading-zeros)
- X (calc-change-mode '(calc-word-size calc-previous-modulo)
- X (list n (math-power-of-2 (math-abs n)))
- X calc-leading-zeros)))
- X (if (< n 0)
- X (message "Binary word size is %d bits (2's complement)." (- n))
- X (message "Binary word size is %d bits." n)))
- )
- X
- X
- X
- X
- X
- ;;; d-prefix mode commands.
- X
- (defun calc-radix (n)
- SHAR_EOF
- true || echo 'restore of calc-bin.el failed'
- fi
- echo 'End of part 9'
- echo 'File calc-bin.el is continued in part 10'
- echo 10 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-